/**
 * interface for data info
 */
export interface IDataInfo {
    type: string;
    toString(): string;
}

/**
 * os info
 */
export class OsInfo implements IDataInfo {
    public type: string = "os";
    public name: string;
    public version?: string;

    constructor(name?: string, version?: string) {
        this.name = name || "ohos";
        this.version = version;
    }

    public toString(): string {
        return `${this.type} ${this.name} ${this.version}`;
    }
}

/**
 * device info
 */
export class DeviceInfo implements IDataInfo {
    public type: string = 'ohos-device';
    public deviceId: string;
    public deviceName?: string;
    public version?: string;

    constructor(deviceId?: string) {
        this.deviceId = deviceId || '';
    }

    public toString(): string {
        return `${this.deviceId}`;
    }
}

/**
 * app info
 */
export class AppInfo implements IDataInfo {
    public type: string = 'app';
    public name: string;
    public pid?: number;
    public version?: string;
 
    constructor(name?: string, pid?: number, version?: string) { 
        this.name = name || '';
        this.pid = pid;
        this.version = version;
    }

    public toString(): string {
        return `${this.name}`;
    }
}

/**
 * url info
 */
export class UrlInfo implements IDataInfo {
    public type: string = 'url';
    public url: string;
    public mappingUrl?: string;
 
    public toString(): string {
        return `${this.url}`;
    }
}

/**
 * heap file info
 */
export class HeapFileInfo implements IDataInfo {
    public type: string = 'heap';
    public name: string;
    public path: string;
    public size?: number;
    public region?: string;
    public scene?: string;
    public url?: UrlInfo;
    public createTime?: number = 0;  // create time

    constructor(path: string) {
        this.path = path;
    }

    public toString(): string {
        return `${this.name}:${this.path}`;
    }
}

/**
 * heap infos
 */
export class HeapInfos {
    public osInfo?: OsInfo;
    public deviceInfo?: DeviceInfo;
    public appInfo?: AppInfo;
    public heapFileInfo?: HeapFileInfo;
    
    constructor(os?: OsInfo, device?: DeviceInfo, app?: AppInfo, heapFile?: HeapFileInfo) {
        this.osInfo = os;
        this.deviceInfo = device;
        this.appInfo = app;
        this.heapFileInfo = heapFile;
    }
}